<html layout:decorate="~{default/layout}" xmlns:layout="http://www.w3.org/1999/xhtml">
<head>
    <script>

    </script>
</head>
<body>
<div layout:fragment="content">
    <div class="main-content-inner">

        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="#">主页</a>
                </li>
                <li class="active">客户购车系统</li>
                <li class="active">客户购车需求</li>
            </ul><!-- /.breadcrumb -->
        </div>

        <div class="page-content">
            <div class="search_condition">
                <form id="search-form">
                    意向程度:
                    <select name="Q_LIKE_statename" class="search-data" style="width:100px;">
                        <option value="">全部</option>
                        <option th:each="value:${stateList}" th:value="${value}" th:text="${value}">
                    </select>
                    时间范围:
                    <div style="display: inline-block" id="time_select">
                        <input class="form_date search-data"
                            style="width:150px; background-color: white !important;"
                            type="text" placeholder="开始时间"
                            id="start_time_select" data-link-field="start_time" data-link-format="yyyy-mm-dd"
                            readonly>
                        <span>至</span>
                        <input class="form_date search-data"
                            style="width:150px; background-color: white !important;"
                            type="text" placeholder="结束时间"
                            id="end_time_select" data-link-field="end_time" data-link-format="yyyy-mm-dd"
                            readonly>
                        <input type="hidden" id="start_time" name="Q_GTE_newtime" class="search-data">
                        <input type="hidden" id="end_time" name="Q_LTE_newtime" class="search-data">
                    </div>
                    <div class="space-4"></div>
                    姓名:<input type="text" name="Q_LIKE_customername" class="search-data">
                    手机:<input type="text" name="Q_LIKE_customerphone" class="search-data">
                    车型:<input type="text" name="Q_LIKE_carmodel" class="search-data">
                    员工:<input type="text" name="Q_LIKE_createUser" class="search-data">
                    <button type="button" id="search-btn" class="btn btn-primary btn-search" >搜索</button>
                    <a type="button"  onclick="doExport('/project/userManage/user_export')" class="btn btn-info btn-search export">导出</a>
                </form>
            </div>
            <div class="main-body">
            
            <table id="dataTable" data-url="/project/userManage/user_data" data-page-list=[]  data-striped="true"
                   data-pagination="true" data-page-size="15" data-cache="false" data-toolbar-align="right">

            </table>
            <script>
                function doExport(url) {
                    var params = '';
                    $(".search-data").each(function () {
                        var key = $(this).attr("name");
                        var val = $(this).val();
                        params+='<input type="hidden" name="'+key+'" value="'+val+'"/>';
                    });
                    $('<form method="post" target="_blank" role="form" action="'+url+'" hidden="hidden">'+
                        params +'</form>') .appendTo('body').submit().remove();
                }
                //过程报警
                var dataFormat_user = [{
                    checkbox: true
                },{
                    field:'id',
                    title:'id',
                    visible:false
                },{
                    field:'budgetlimitmax',
                    title:'budgetlimitmax',
                    visible:false
                },{
                    field: 'customername',
                    title: '客户姓名',
                    sortable:true
                },{
                    field: 'customerphone',
                    title: '客户手机',
                    sortable:true

                }, {
                    field: 'customersource',
                    title: '客户来源',
                    sortable:true
                }, {
                    field: 'city',
                    title: '所在城市',
                    sortable:true
                }, {
                    field: 'statename',
                    title: '意向等级',
                    sortable:true
                }, {
                    field: 'budgetlimitmin',
                    title: '购车预算',
                    sortable:true,
                    formatter:function (value,row,index) {
                        //console.log('index:'+index);
                        //console.log('row:'+ row);
                        return value+'-'+row.budgetlimitmax+' 万';
                    }
                }, {
                    field: 'carmodel',
                    title: '需求车型',
                    sortable:true
                }, {
                    field: 'requirementyear',
                    title: '年限要求',
                    sortable:true
                }, {
                    field: 'requirementmileage',
                    title: '里程要求',
                    sortable:true
                }, {
                    field: 'requirementcolor',
                    title: '颜色要求',
                    sortable:true
                }, {
                    field: 'requirementsettledIn',
                    title: '落户地',
                    sortable:true
                }, {
                    field: 'requirementmileage',
                    title: '里程要求',
                    sortable:true
                }, {
                    field: 'note',
                    title: '备注',
                    sortable:true
                }, {
                    field: 'sumparam',
                    title: '需求积分',
                    sortable:true
                },{
                    field: 'update_time',
                    title: '修改时间',
                    sortable:true
                }, {
                    field: 'update_time',
                    title: '操作',
                    sortable:true,

                    field: 'updateUser',
                        formatter:function (value,row,index) {
                            //console.log('index:'+index);
                            //console.log(value==null);
                            var txt= (value==null ? '': value )+' <a onclick="deleteUserMange('+row.id+')" >删除</a>';
                            txt+=' <a onclick="showDg( '+row.id+')" >查看</a>';
                            return txt;
                        }
                }];


                window.onload = function () {
                    getTable(dataFormat_user, "dataTable");
                };

                function showDg(id){
                    var url = '/project/userManage/show_user_detail?id='+ id ;
                    showInDialog(url);
                }
                function deleteUserMange(id) {
                    var data={id:id};
                    var url ='/project/userManage/user_del';
                    if (!confirm("您确定要删除吗？")) {
                        return false;
                    } else {

                        $.ajax({
                            type: "POST",
                            url: url,
                            data: data,
                            dataType: "json",
                            success: function (result) {
                                console.log(result);
                                if (typeof result == 'object') {
                                    var data = result;
                                } else {
                                    var data = eval('(' + result + ')');
                                }
                                $('#defaultForm').prev().find("button").click();
                                $("#dataTable").bootstrapTable("selectPage", 1);
                            }
                        });
                    }
                }


                /**
                 * 限制开始时间和结束时间不能互相超过
                 */
                $(function () {
                    $("#start_time_select").datetimepicker({
                        bootcssVer: 3,   //设置读取bootstrap3，否则默认读取bootstrap2，左右箭头会不见
                        startView: 2,
                        format: "yyyy-mm-dd",
                        minView: "month",
                        todayBtn: "linked",
                        todayHighlight: true,
                        language: "zh-CN",
                        showMeridian: true,
                        autoclose: true
                    }).on('changeDate', function (ev) {
                        $('#start_time').val($('#start_time').val()+' 00:00:00');
                    });
                    $("#end_time_select").datetimepicker({
                        bootcssVer: 3,   //设置读取bootstrap3，否则默认读取bootstrap2，左右箭头会不见
                        startView: 2,
                        minView: "month",
                        format: "yyyy-mm-dd",
                        todayBtn: "linked",
                        todayHighlight: true,
                        language: "zh-CN",
                        autoclose: true,
                        showMeridian: true
                    }).on('changeDate', function (ev) {
                        $('#end_time').val($('#end_time').val()+' 23:59:59');
                    });
                });

            </script>
        </div>
        </div>
        
    </div>

</div>
</body>
</html>